package com.jt.base.utils;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author longheping
 * @date 2018/8/3 15:59
 */
public class JsonDataFilterUtil {

  public static String jsonFilterWithObject(Object o, String... properties){
    SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter(properties);
    return JSONObject.toJSONString(o,simplePropertyPreFilter);
  }

  public static String jsonFilterWithR(R r, String... properties){
    List<String> list = Lists.newArrayList(properties);
    list.add("code");
    list.add("msg");
    list.add("data");
    return jsonFilterWithObject(r,list.toArray(new String[0]));
  }

}
